﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nhibernate.GuitarStore.Common;
using NHibernate;
using NHibernate.Criterion;

namespace Nhibernate.GuitarStore.DataAccess
{
    public class NHibernateInventory : NHibernateBase
    {
        public IList<Inventory> ExecuteICriteriaOrderBy(string orderBy)
        {
            using (ITransaction transaction = Session.BeginTransaction())
            {
                try
                {
                    IList<Inventory> result = Session.CreateCriteria<Inventory>()
                                             .AddOrder(Order.Asc(orderBy))
                                             .List<Inventory>();
                    transaction.Commit();
                    return result;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
    }
}
